package com.ruoyi.eam.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamLocation;
import com.ruoyi.eam.service.IEamLocationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 存放位置Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/location")
public class EamLocationController extends BaseController
{
    @Autowired
    private IEamLocationService eamLocationService;

    /**
     * 查询存放位置列表
     */
    //@RequiresPermissions("system:location:list")
    @GetMapping("/list")
    public TableDataInfo list(EamLocation eamLocation)
    {
        startPage();
        List<EamLocation> list = eamLocationService.selectEamLocationList(eamLocation);
        return getDataTable(list);
    }

    /**
     * 导出存放位置列表
     */
    //@RequiresPermissions("system:location:export")
    @Log(title = "存放位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamLocation eamLocation)
    {
        List<EamLocation> list = eamLocationService.selectEamLocationList(eamLocation);
        ExcelUtil<EamLocation> util = new ExcelUtil<EamLocation>(EamLocation.class);
        util.exportExcel(response, list, "存放位置数据");
    }

    /**
     * 获取存放位置详细信息
     */
    //@RequiresPermissions("system:location:query")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return success(eamLocationService.selectEamLocationByLocationId(locationId));
    }

    /**
     * 新增存放位置
     */
    //@RequiresPermissions("system:location:add")
    @Log(title = "存放位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamLocation eamLocation)
    {
        return toAjax(eamLocationService.insertEamLocation(eamLocation));
    }

    /**
     * 修改存放位置
     */
    //@RequiresPermissions("system:location:edit")
    @Log(title = "存放位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamLocation eamLocation)
    {
        return toAjax(eamLocationService.updateEamLocation(eamLocation));
    }

    /**
     * 删除存放位置
     */
    //@RequiresPermissions("system:location:remove")
    @Log(title = "存放位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(eamLocationService.deleteEamLocationByLocationIds(locationIds));
    }
}
